#include <iostream>
#include <string.h>
#include <memory>
using namespace std;

class String{
    public: 
        String(const char * str) {
            cout << "String(const char *)" << endl;
            if (str) {
                m_ptr = new char[strlen(str) + 1];
                strcpy(m_ptr, str);
            } else {
                m_ptr = (char *)str;
            }
        }
        ~String() {
            cout << "~String()" <<endl;
            if (m_ptr) {
                delete [] m_ptr;
            }
        }
        void show(void) const{
            cout << m_ptr << endl;
        }
    private:
        char * m_ptr;    
};
int main(int argc, char const *argv[])
{


    // unique_ptr 的赋值函数和拷贝构造函数是删除的状态， 它不能用在有拷贝构造函数和赋值场合
    unique_ptr<String> smart3(new String("hello"));
    unique_ptr<String> smart4(new String("world"));
    smart3->show();
    (*smart4).show();
    cout << "-----------" << endl;
    smart3 = std::move(smart4);
    smart3->show();

    return 0;
}
